package com.jun.leetcode.chapter1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

/**
 * 描述:这里用的滑动窗口来实现，还有一种优化的滑动窗口
 *
 * @author Administrator
 * @create 2018-09-17 18:59
 */
public class Solution3 {

    public int lengthOfLongestSubstring(String s) {
        int result = 0 ;
        Set<Character> set = new HashSet();

        int beginIndex = 0 ;
        int endIndex = 0;
        int charLength = s.toCharArray().length;
        while ( beginIndex < charLength  && endIndex < charLength  ){
            if ( !set.contains(s.charAt(endIndex))){
                set.add(s.charAt(endIndex));
                endIndex++;
                result = Math.max( result , endIndex - beginIndex);
            }else {
                set.remove(s.charAt(beginIndex));
                beginIndex++;
            }
        }
        return result;
    }
}
class MainClass {
    public static String stringToString(String input) {
        if (input == null) {
            return "null";
        }
        return input;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = in.readLine()) != null) {
            String s = stringToString(line);

            int ret = new Solution3().lengthOfLongestSubstring(s);

            String out = String.valueOf(ret);

            System.out.print(out);
        }
    }
}